const CONFIG = require('../../config.js');
Page({
	data: {
		navBgColor: '-webkit-gradient(linear, 0% 0%, 0% 100%,from(#1b64e5), to(#39a9ed))',
		loginInfo:'',
		proTitle: '',
		proLists: [
			{
				name: '基本信息',
				code: 'A',
				isShow: true,
				isSave: false,
			},  {
				name: '企业信息',
				code: 'B',
				isShow: true,
				isSave: false
			}, {
				name: '工作信息',
				code: 'C',
				isShow: true,
				isSave: false
			}, {
				name: '房屋信息',
				code: 'HouseList',
				isShow: true,
				isSave: false,
				open: true,
			}, {
				name: '车辆信息',
				code: 'CarList',
				isShow: true,
				isSave: false,
				open: true
			}, {
				name: '保单信息',
				code: 'InsuranceList',
				isShow: true,
				isSave: false,
				open: true
			}, {
				name: '征信信息',
				code: 'E',
				isShow: true,
				isSave: false
			},  {
				name: '负债信息',
				code: 'F',
				isShow: true,
				isSave: false
			}, {
				name: '流水信息',
				code: 'G',
				isShow: true,
				isSave: false
			}, {
				name: '法律信息',
				code: 'H',
				isShow: true,
				isSave: false
			}
		],
		showlists:{
			HouseList: false,
			CarList: false,
			InsuranceList: false,
		},
		baseInfos: {
			houseList:[],
			carList: [],
			insuranceList: [],
		},
		isShowB: true,
		houseChecks: [],
		carChecks: [],
		insuranceChecks: [],
		productType: '',
	},

	setProInfo(){
		this.baseInfos = baseInfos;
		for(let key in this.baseInfos){
			this.data.proLists.forEach(item => {
				let code = item.code.toLowerCase();
				let mykey = key.toLowerCase();
				if(code === mykey){
					if(productType === '10001' || productType === '10002'){   // 房屋
						if (item.code === 'C' || item.code === 'CarList' || item.code === 'InsuranceList'){
							item.isShow = false;
						}
					}else if(productType === '20001' || productType === '20002'){ // 企业贷
						if (item.code === 'C' || item.code === 'HouseList' || item.code === 'CarList' || item.code === 'InsuranceList'){
							item.isShow = false;
						}
					}else if(productType === '40001'){ // 车辆
						if (item.code === 'B' || 
							item.code === 'C' || 
							item.code === 'G' || 
							item.code === 'H' || 
							item.code === 'HouseList' || 
							item.code === 'InsuranceList'){
							item.isShow = false;
						}
					}else if(productType === '30001'){ // 按揭房
						if (item.code === 'F' || 
							item.code === 'CarList' || 
							item.code === 'InsuranceList'){
							item.isShow = false;
						}
					}else if(productType === '30002' || productType === '30006'){ // 公积金贷款,打卡工资信用贷
						if (item.code === 'F' || 
							item.code === 'B' || 
							item.code === 'HouseList' || 
							item.code === 'CarList' || 
							item.code === 'InsuranceList'){
							item.isShow = false;
						}
					}else if(productType === '30004'){ // 按揭车
						if (item.code === 'F' || 
							item.code === 'G' || 
							item.code === 'H' || 
							item.code === 'HouseList' || 
							item.code === 'InsuranceList'){
							item.isShow = false;
						}
					}
					if(typeof this.baseInfos[key] ==='object'){
						item.isSave = !!this.baseInfos[key].length;
						item.proList = this.baseInfos[key];
					}else{
						item.isSave = !!this.baseInfos[key];
					}
				}
			});
		}
	},

	// 获取基本信息
	getBaseInfo(){
		let that = this;
		wx.request({
			url: CONFIG.host + "/system/appInfoController/getCustomerProductDetailInfo",
			data: {
				itemType: 'A',
			},
			method: "GET",
			header: {
				'content-type': 'application/json',
				'Authorization': this.data.loginInfo.token
			},
			success: res => {
				if(res.data.code === 'success'){
					let data = res.data.data;
					for (let i = 0; i < data.length; i++) {
						console.log(data[i].itemCode, data[i].itemValue,i)
						if (data[i].itemCode === 'A009' && data[i].itemValue === '1') {
							that.data.proLists.forEach((item, index) => {
								if (item.code === 'B') {
									that.proLists.splice(index, 1);
								}
							})
						}
					}
				}
			},fail: function (error) {
				console.log(error);
			}
		})
	},

  	onLoad: function (options) {
		let loginInfo = wx.getStorageSync('loginInfo') || '';
		if(loginInfo){
			this.setData({
				loginInfo: JSON.parse(loginInfo)
			})
			this.getBaseInfo();
		}
	  },
	  
	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {
		
	},
})
